package crazyboyfeng.autodroid.utils;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Set;
import java.util.TreeSet;

import crazyboyfeng.autodroid.R;

/**
 * Tools for Week Day
 * @author Kelvin
 *
 */
public class WeekTools {
	
	private static HashMap vMap=new HashMap();
	private static int WORKDAY=15;
	private static int ALLTHEWEEK=1315;
	
	public static void init(){
		 GlobalContext context = GlobalContext.getInstance();
		 CharSequence[] items=context.getResources().getStringArray(R.array.addnewtask_type_mlist);
		 CharSequence[] values = context.getResources().getStringArray(R.array.addnewtask_type_values_mlist);
		 for(int i=0;i<items.length;i++){
			 vMap.put(values[i].toString(), items[i].toString());
		 }
	}
	
	public static String getWeekMsg(String[] values){
		if(vMap.isEmpty()){
			init();
		}
		StringBuilder sMsg = new StringBuilder();
		int count =0;
		for(int i=0;i<values.length;i++){
			if(values[i].length()>0){
				count = count + Integer.parseInt(values[i].toString());
				sMsg.append(vMap.get(values[i].toString()));
				sMsg.append(" ");
			}
		}
		if(count==WORKDAY){
			return "工作日";
		}
		if(count==ALLTHEWEEK){
			return "每一天";
		}
		return sMsg.toString();
	}
	
	public static String getWeekMsg(Set<String> values){
		
		if(values.isEmpty()) return "仅一次";
		
		if(vMap.isEmpty()){
			init();
		}
		
		TreeSet<String> mValues = new TreeSet<String>();
		mValues.addAll(values);
		String[] sValue = mValues.toArray(new String[0]);
		
		
		return getWeekMsg(sValue);
	}
	
	public static int getNowWeek(){
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date(System.currentTimeMillis()));
		int week = cal.get(Calendar.DAY_OF_WEEK);
		if(week==1){
			return 700;
		}else if(week==2){
			return 1;
		}else if(week==3){
			return 2;
		}else if(week==4){
			return 3;
		}else if(week==5){
			return 4;
		}else if(week==6){
			return 5;
		}else if(week==7){
			return 600;
		}
		return 0;
	}
	
}
